<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html-el" %>
<%@ taglib uri="http://amc.af.mil/radtaglibrary" prefix="rad" %>
<%@ taglib uri="http://amc.af.mil/portal-el" prefix="portal" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
    <title>Edit Item</title>
    <link type="text/css" rel="stylesheet" href="yui/build/calendar/assets/skins/sam/calendar.css"/>
    <link type="text/css" rel="stylesheet" href="yui/build/calendar/assets/skins/sam/calendar-skin.css"/>
    <link type="text/css" rel="stylesheet" href="yui/build/button/assets/skins/sam/button.css"/>
    <script type="text/javascript" src="js/adpetracker.js"></script>
    <script type="text/javascript" src="yui/build/yuiloader/yuiloader-beta-min.js"></script>
    <script type="text/javascript" src="yui/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="yui/build/calendar/calendar.js"></script>
    <style type="text/css">
        #calContainer {
            display: none;
            position: absolute;
            left: 200px;
            top: 300px;
            z-index: 1
        }
    </style>
</head>

<body>

<rad:useBean id="adpeAccountViewHelper"/>
<rad:useBean id="equipmentItemViewHelper"/>
<rad:useBean id="equipmentTypeViewHelper"/>
<rad:useBean id="manufacturerViewHelper"/>
<rad:useBean id="itemModelViewHelper"/>

<c:set var="type" value="${equipmentTypeViewHelper.equipmentType}"/>
<c:set var="item" value="${equipmentItemViewHelper.item}"/>

<div id="portal-left-bar">
    <jsp:include page="../navigation/navigationMenu.jsp"/>
</div>

<div id="portal-content">
<div id="addEquipmentItem">
<portal:box title="Edit Equipment Item" style="width:800px">
<html:form method="post" action="equipmentItem/edit.do">
<html:hidden property="itemId" value="${item.id}"/>

<p><label for="itemTypeId">Item Type</label>
    <c:choose>
        <c:when test="${type eq null}">
            <html:select property="itemTypeId" styleId="itemTypeId"
                    onchange="javascript:chainSelect('itemTypeId','manufacturerId','getManufacturerByEquipmentTypeAction.do')">
                <html:option value="">Choose One</html:option>
                <html:optionsCollection name="equipmentTypeViewHelper"
                                        property="all"
                                        label="typeDescription"
                                        value="id"
                                        filter="false"/>
            </html:select>
        </c:when>
        <c:otherwise>
            <html:select property="itemTypeId" value="${type.id}" styleId="itemTypeId"
                    onchange="javascript:chainSelect('itemTypeId','manufacturerId','getManufacturerByEquipmentTypeAction.do')">
                <html:optionsCollection name="equipmentTypeViewHelper"
                                        property="all"
                                        label="name"
                                        value="id"
                                        filter="false"/>
            </html:select>
        </c:otherwise>

    </c:choose>

</p>

<p><label for="ipmsNumber">IPMS Number</label>
    <html:text property="ipmsNumber" maxlength="14" value="${item.ipms}"/></p>

<p><label for="serialNumber">Serial Number</label>
    <html:text property="serialNumber" maxlength="25" value="${item.serial}"/></p>

<p>
    <label for="manufacturer">Manufacturer</label>
<%--    <html:select property="manufacturerId" onchange="javascript:getModelsByManufacturer()"
                 styleId="manufacturerId" value="${item.itemModel.manufacturer.id}">--%>
    <html:select property="manufacturerId" onchange="javascript:chainSelect('manufacturerId','modelId','itemModel/getByManufacturer.do')"
                 styleId="manufacturerId" value="${item.itemModel.manufacturer.id}">
        <html:optionsCollection name="manufacturerViewHelper"
                                property="all"
                                label="name"
                                value="id"
                                filter="false"/>
    </html:select>
</p>
<%--<html:text property="manufacturer" maxlength="25"/>--%>

<label for="model">Model</label>

<p>
    <html:select property="modelId" styleId="modelId" value="${item.itemModel.id}">
        <html:optionsCollection filter="false"
                                name="itemModelViewHelper"
                                property="all"
                                label="name"
                                value="id"/>
    </html:select>
</p>

<p><label for="description">Description</label>
    <html:text property="description" maxlength="100" value="${item.description}"/></p>

<p><label for="location">Location</label>
    <html:text property="location" styleId="location" maxlength="255" value="${item.location}"/>
</p>

<p>
    <label for="purchaseDate">Purchase Date</label>
    <html:text property="purchaseDate" styleId="purchaseDate" maxlength="15" readonly="true" value="${equipmentItemViewHelper.formattedPurchaseDate}"/>
    <button type="button" id="showCalendar">
        <img src="images/calendar-icon.gif" alt="Calendar"/>
    </button>

    <div id="parent1" class="yui-skin-sam">
        <div id="calContainer"></div>
    </div>

</p>

<p><label for="purchaseCost">Purchase Cost</label>
    <html:text property="purchaseCost" maxlength="12" value="${item.originalCost}"/></p>

<p><label for="adpeAccountId">ADPE Account</label>
    <html:select property="adpeAccountId" value="${item.account.id}">
        <html:optionsCollection filter="false"
                                name="adpeAccountViewHelper"
                                property="allAccounts"
                                label="name"
                                value="id"/>

    </html:select></p>

<p><label for="itemConditionId">Item Condition</label>
    <c:choose>
        <c:when test="${item.itemCondition eq null}">
            <html:select property="itemCondition">
                <html:option value="0">Serviceable</html:option>
                <html:option value="1">Unserviceable</html:option>
            </html:select>
        </c:when>
        <c:otherwise>
            <html:select property="itemCondition" value="${item.itemCondition.ordinalValue}">
                <html:option value="0">Serviceable</html:option>
                <html:option value="1">Unserviceable</html:option>
            </html:select>
        </c:otherwise>
    </c:choose>
</p>

<p><label for="itemStatusId">Item Status</label>
    <c:choose>
        <c:when test="${item.itemStatus eq null}">
            <html:select property="itemStatusId">
                <html:option value="0">Active</html:option>
                <html:option value="1">Inactive</html:option>
                <html:option value="2">Pending DRMO</html:option>
                <html:option value="3">DRMO</html:option>
                <html:option value="4">Pending ROS</html:option>
                <html:option value="5">ROS</html:option>
            </html:select>
        </c:when>
        <c:otherwise>
            <html:select property="itemStatusId" value="${item.itemStatus.ordinal}">
                <html:option value="0">Active</html:option>
                <html:option value="1">Inactive</html:option>
                <html:option value="2">Pending DRMO</html:option>
                <html:option value="3">DRMO</html:option>
                <html:option value="4">Pending ROS</html:option>
                <html:option value="5">ROS</html:option>
            </html:select>
        </c:otherwise>
    </c:choose>
</p>

<p><label for="lastInventoryDate">Last Inventory Date</label>
    <html:text property="lastInventoryDate"/>
</p>
<html:submit value="Edit"/>
</html:form>
</portal:box>
</div>
</div>

<script type="text/javascript">
    YAHOO.namespace("addItems.purchaseDateCalendar");
    YAHOO.addItems.purchaseDateCalendar.init = function() {

        YAHOO.addItems.purchaseDateCalendar.calendar = new YAHOO.widget.Calendar("pdCalendar",
                "calContainer",
                {close: true, title: 'Purchase Date'});

        YAHOO.addItems.purchaseDateCalendar.calendar.render();
        YAHOO.addItems.purchaseDateCalendar.calendar.hide();

        YAHOO.util.Event.addListener('showCalendar', 'click', showCalendar);

        YAHOO.addItems.purchaseDateCalendar.calendar.selectEvent.subscribe(handleSelect,
                YAHOO.addItems.purchaseDateCalendar.calendar,
                true);
    }

    function showCalendar() {
        YAHOO.addItems.purchaseDateCalendar.calendar.show();

    }

    function handleSelect(type, args, obj) {

        var allDates = args[0];
        var singleDate = allDates[0];

        var months = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];

        var year = singleDate[0];
        var month = singleDate[1] - 1;
        var day = singleDate[2];

        var formattedDate = day + '-' + months[month] + '-' + year;

        document.getElementById('purchaseDate').value = formattedDate;

        YAHOO.addItems.purchaseDateCalendar.calendar.hide();
    }

    YAHOO.util.Event.onDOMReady(YAHOO.addItems.purchaseDateCalendar.init);

</script>
</body>
</html>